package com.yungu.swift.system.finance.service.impl;

import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.system.finance.dao.FinancePrepayMapper;
import org.apache.commons.collections4.CollectionUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.system.finance.model.dto.FinancePrepayDto;
import com.yungu.swift.system.finance.service.FinancePrepayService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * FinancePrepayServiceImpl
 **/

@Service
public class FinancePrepayServiceImpl extends BaseServiceImpl<FinancePrepayDto> implements FinancePrepayService {

    @Autowired
    private FinancePrepayMapper financePrepayMapper;

    @Override
    protected IMapper<FinancePrepayDto> getMapper() {
        return financePrepayMapper;
    }

    @Override
    public ResponseData<Boolean> disablePaying(String orderUuid) {
        return ResponseData.buildSuccessResponse("关闭正在支付的订单成功",
                financePrepayMapper.disablePaying(orderUuid) > 0);
    }

    @Override
    public ResponseData<FinancePrepayDto> findAvailablePrepay(String orderUuid, String couponUuid, Double money, Integer type) {
        Map<String, Object> params = new HashMap<>(8);
        params.put("orderUuid", orderUuid);
        params.put("couponUuid", couponUuid);
        params.put("money", money);
        params.put("type", type);
        List<FinancePrepayDto> list = financePrepayMapper.findAvailablePrepay(params);
        if (CollectionUtils.isNotEmpty(list)) {
            return ResponseData.buildSuccessResponse(list.get(0));
        }
        return ResponseData.buildSuccessResponse(null);
    }
}